package com.lanou.dllo.findfood.adpter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.dllo.findfood.R;
import com.lanou.dllo.findfood.entity.Speacil_list;
import com.lanou.dllo.findfood.tools.StringUtil;
import com.lanou.dllo.findfood.tools.TimeUtil;
import com.lanou.dllo.findfood.volley.VolleySington;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by dllo on 15/10/26.
 */
public class SpeacialRecyerAdpter extends RecyclerView.Adapter<SpeacialRecyerAdpter.RecyerAdpter> {
    List<Speacil_list> lists;

    public void addData(List<Speacil_list> list) {
        lists = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyerAdpter onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.recy_speal_item, null);

        return new RecyerAdpter(view);
    }

    @Override
    public void onBindViewHolder(RecyerAdpter holder, int position) {

        if (lists != null && lists.size() > 0) {
            Speacil_list list = lists.get(position);
            holder.spfooddisption.setText(list.getDescription());
            holder.spfoodTitle.setText(list.getTitle());
            holder.spuserName.setText(list.getAccount().getNickname());
            holder.praisescore.setText(list.getPraise_score());
            holder.parise.setText(list.getPraise());

//美食照片
            String imge = list.getImage();
            getBitmap(imge, holder.spfoodImage);
//美食发表者
            String avater = list.getAccount().getAvatar();
            getBitmap(avater, holder.speuserimge);
//美食评论者
//            holder.praAvater.setText(list.getPraise_member().get(0).getNickname());
            String url = list.getPraise_member().get(0).getAvatar();
            getBitmap(url, holder.spnikAvater);
            String str =list.getCreate_time();



        }
        holder.position = position;
    }

    private void getBitmap(String url, final NetworkImageView networkImageView) {
        ImageLoader imageLoader = VolleySington.getInstance().getImageLoader();
        networkImageView.setDefaultImageResId(R.mipmap.ic_launcher);
        networkImageView.setErrorImageResId(R.mipmap.ic_launcher);
        networkImageView.setImageUrl(url, imageLoader);


    }


    @Override
    public int getItemCount() {
        return lists != null && lists.size() > 0 ? lists.size() : 0;
    }

    class RecyerAdpter extends RecyclerView.ViewHolder {
        private NetworkImageView speuserimge, spfoodImage, spnikAvater;
        private TextView spuserName, praisescore, spfoodTitle,
                timeNew,
        spfooddisption, parise, praAvater;
        private int position;

        public RecyerAdpter(View itemView) {
            super(itemView);
            speuserimge = (NetworkImageView) itemView.findViewById(R.id.speuserimge);

            spfooddisption = (TextView) itemView.findViewById(R.id.spfooddisption);
            spnikAvater = (NetworkImageView) itemView.findViewById(R.id.spnikAvater);
            spfoodImage = (NetworkImageView) itemView.findViewById(R.id.spfoodImage);
            timeNew = (TextView) itemView.findViewById(R.id.timeNew);
            spuserName = (TextView) itemView.findViewById(R.id.spuserName);
            praisescore = (TextView) itemView.findViewById(R.id.praisescore);
            spfoodTitle = (TextView) itemView.findViewById(R.id.spfoodTitle);
            spfooddisption = (TextView) itemView.findViewById(R.id.spfooddisption);
            parise = (TextView) itemView.findViewById(R.id.parise);
            praAvater = (TextView) itemView.findViewById(R.id.praAvater);


        }
    }
}
